Skip to content

Conversation

@DiegoCivi
Copy link
Contributor

@DiegoCivi DiegoCivi commented Nov 14, 2025

Fix BoundedInt Sub libfunc

The previous implementation of the sub libfunc had some cases in which it failed to return the correct result. We decided to change the algorithm to one that is simpler to understand and is mathematically correct.

We have C = A - B, where all of them are BoundedInt. We represent the a BoundedInt as:

  • X = Xo + Xd, where
    • X is a BoundedInt.
    • Xo is the lower bound of the BoundedInt range.
    • Xd is the offset.

So we want to get Cd and we have Co + Cd = ( Ao + Ad ) - ( Bo + Bd ) -> Cd = Ao + Ad - Bo - Bd - Co.

Closes #1449

Introduces Breaking Changes?

No.

Checklist

  • Linked to Github Issue.
  • Unit tests added.
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.

@codecov-commenter
Copy link

codecov-commenter commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 95.95960% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.76%. Comparing base (79da595) to head (1b72852).

Files with missing lines Patch % Lines
src/libfuncs/bounded_int.rs 95.95% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1465      +/-   ##
==========================================
+ Coverage   81.69%   81.76%   +0.06%     
==========================================
  Files         105      105              
  Lines       26047    26109      +62     
==========================================
+ Hits        21279    21347      +68     
+ Misses       4768     4762       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Nov 14, 2025

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 2.598 ± 0.032 2.555 2.653 1.00
base dict_insert.cairo (AOT) 2.625 ± 0.022 2.597 2.672 1.01 ± 0.02

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 2.725 ± 0.061 2.623 2.801 1.04 ± 0.03
head dict_insert.cairo (AOT) 2.633 ± 0.054 2.561 2.716 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 2.418 ± 0.031 2.371 2.470 1.06 ± 0.02
base dict_snapshot.cairo (AOT) 2.285 ± 0.026 2.239 2.324 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 2.370 ± 0.037 2.315 2.432 1.02 ± 0.02
head dict_snapshot.cairo (AOT) 2.324 ± 0.030 2.279 2.390 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 2.688 ± 0.028 2.628 2.739 1.01 ± 0.01
base factorial_2M.cairo (AOT) 2.663 ± 0.016 2.648 2.696 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 2.852 ± 0.039 2.771 2.916 1.01 ± 0.02
head factorial_2M.cairo (AOT) 2.818 ± 0.018 2.795 2.847 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 2.270 ± 0.030 2.220 2.323 1.03 ± 0.02
base fib_2M.cairo (AOT) 2.200 ± 0.036 2.123 2.261 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 2.355 ± 0.034 2.306 2.396 1.02 ± 0.02
head fib_2M.cairo (AOT) 2.301 ± 0.040 2.235 2.355 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base heavy_circuit.cairo (JIT) 15.199 ± 0.088 15.109 15.335 1.02 ± 0.01
base heavy_circuit.cairo (AOT) 14.884 ± 0.084 14.731 15.016 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head heavy_circuit.cairo (JIT) 14.875 ± 0.098 14.672 14.992 1.04 ± 0.01
head heavy_circuit.cairo (AOT) 14.341 ± 0.102 14.155 14.460 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 2.412 ± 0.015 2.386 2.430 1.07 ± 0.01
base linear_search.cairo (AOT) 2.250 ± 0.018 2.217 2.276 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 2.539 ± 0.015 2.501 2.554 1.06 ± 0.01
head linear_search.cairo (AOT) 2.401 ± 0.016 2.380 2.428 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 2.535 ± 0.020 2.511 2.567 1.08 ± 0.02
base logistic_map.cairo (AOT) 2.357 ± 0.035 2.316 2.416 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 2.647 ± 0.038 2.597 2.698 1.08 ± 0.02
head logistic_map.cairo (AOT) 2.458 ± 0.026 2.410 2.494 1.00

@github-actions
Copy link

github-actions bot commented Nov 14, 2025

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 10.954 ± 0.076 10.820 11.115 4.44 ± 0.07
cairo-native (embedded AOT) 2.467 ± 0.034 2.402 2.510 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.538 ± 0.014 2.516 2.557 1.03 ± 0.02

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 528.4 ± 6.8 520.4 540.3 1.00
cairo-native (embedded AOT) 2148.8 ± 21.1 2115.1 2181.3 4.07 ± 0.07
cairo-native (embedded JIT using LLVM's ORC Engine) 2264.2 ± 34.4 2227.8 2340.9 4.28 ± 0.09

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.728 ± 0.019 4.713 4.772 1.83 ± 0.01
cairo-native (embedded AOT) 2.579 ± 0.008 2.565 2.593 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.628 ± 0.023 2.606 2.678 1.02 ± 0.01

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.695 ± 0.014 4.670 4.713 2.24 ± 0.01
cairo-native (embedded AOT) 2.097 ± 0.008 2.080 2.109 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.145 ± 0.024 2.125 2.206 1.02 ± 0.01

Benchmark for program heavy_circuit

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 9.648 ± 0.077 9.476 9.769 1.00
cairo-native (embedded AOT) 13.618 ± 0.072 13.491 13.712 1.41 ± 0.01
cairo-native (embedded JIT using LLVM's ORC Engine) 13.888 ± 0.089 13.740 14.041 1.44 ± 0.01

Benchmark for program linear_search

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 560.0 ± 3.8 553.7 565.6 1.00
cairo-native (embedded AOT) 2198.8 ± 18.5 2168.4 2225.9 3.93 ± 0.04
cairo-native (embedded JIT using LLVM's ORC Engine) 2354.8 ± 54.8 2314.4 2474.6 4.20 ± 0.10

Benchmark for program logistic_map

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 375.6 ± 2.6 372.7 381.9 1.00
cairo-native (embedded AOT) 2264.6 ± 19.3 2245.0 2314.6 6.03 ± 0.07
cairo-native (embedded JIT using LLVM's ORC Engine) 2443.3 ± 23.2 2420.6 2500.9 6.51 ± 0.08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review bounded_int_sub libfunc

3 participants